package com.intelligentcar.springboot.controller;

import com.intelligentcar.springboot.bean.Vehicle;
import com.intelligentcar.springboot.service.VehicleServer;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class VehicleController {
    @Autowired
    private VehicleServer vehicleServerImpl;

    //车辆管理新增
    @RequestMapping("/vehicleadd")
    @ResponseBody
    public Map vehicleadd(HttpServletRequest req, @RequestBody Vehicle vehicle) {
        Map map = new HashMap();
        map.put("cole", vehicleServerImpl.vehicleadd(req,vehicle));
        return map;
    }

    //查询车辆表所有信息
    @RequestMapping("/lookupvehicle")
    @ResponseBody
    public Map lookupvehicle(@RequestBody Vehicle vehicle) {
        Map map = new HashMap();
        map.put("total", vehicleServerImpl.count());
        map.put("list", vehicleServerImpl.lookupvehicle(new RowBounds((vehicle.getPage() - 1) * vehicle.getSize(), vehicle.getSize())));
        return map;
    }

    //查询车辆表中的单条信息
    @RequestMapping("/queryvehicle")
    @ResponseBody
    public Map queryvehicle(@RequestBody Vehicle vehicle) {
        Map map = new HashMap();
        map.put("total", vehicleServerImpl.count1(vehicle));
        List<Vehicle> list = vehicleServerImpl.queryvehicle(vehicle ,new RowBounds((vehicle.getPage() - 1) * vehicle.getSize(), vehicle.getSize()));
        map.put("list",list);
        return map;
    }

    //修改车辆表的车辆信息
    @RequestMapping("/updatevehicle")
    @ResponseBody
    public Map updatevehiclee( HttpServletRequest req,@RequestBody Vehicle vehicle) {
        Map map = new HashMap();
        int code =vehicleServerImpl.updatevehiclee(req,vehicle);
        map.put("code",code);
        return map;
    }

    //删除车辆表中的车辆信息
    @RequestMapping("/deletevegicle")
    @ResponseBody
    public Map deletevegicle( HttpServletRequest req,@RequestBody Vehicle vehicle){
        System.out.println(vehicle.getId());
        Map map = new HashMap();
        map.put("code",vehicleServerImpl.deletevegicle(req,vehicle));
        return map;
    }

    //查询车辆信息表中的所有车牌号
    @RequestMapping("/selectvehicle")
    @ResponseBody
    public Map selectvegicle(){
        Map map = new HashMap();
        map.put("list",vehicleServerImpl.selectvehicle());
        return map;
    }

    //查询车辆表中的单条信息
    @RequestMapping("/queryvehicle1")
    @ResponseBody
    public Map queryvehicle1(@RequestBody Vehicle vehicle) {
        Map map = new HashMap();
        map.put("total", vehicleServerImpl.count2(vehicle));
        map.put("list",vehicleServerImpl.queryvehicle1(vehicle, new RowBounds((vehicle.getPage()-1)*vehicle.getSize(),vehicle.getSize())));
        return map;
    }
    //查询车辆表中的单条信息
    @RequestMapping("/queryvehicle2")
    @ResponseBody
    public Map queryvehicle2(@RequestBody Vehicle vehicle) {
        System.out.println(vehicle.getState());
        Map map = new HashMap();
        map.put("total", vehicleServerImpl.count3(vehicle));
        map.put("list",vehicleServerImpl.queryvehicle2(vehicle, new RowBounds((vehicle.getPage()-1)*vehicle.getSize(),vehicle.getSize())));
        return map;
    }
    //查询车辆表中的单条信息
    @RequestMapping("/queryvehicle3")
    @ResponseBody
    public Map queryvehicle3(@RequestBody Vehicle vehicle) {
        Map map = new HashMap();
        map.put("total", vehicleServerImpl.count4(vehicle));
        List<Vehicle> list = vehicleServerImpl.queryvehicle3(vehicle, new RowBounds((vehicle.getPage()-1)*vehicle.getSize(),vehicle.getSize()));
        map.put("list",list);
        return map;
    }

}
